package com.douqu.game.core.util.time;

import com.douqu.game.core.config.activity.ActivityHallConfig;
import com.douqu.game.core.e.E_TimeDataType;
import com.douqu.game.core.e.E_TimeDataUnit;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.common.TwoTuple;
import com.douqu.game.core.entity.ext.ChallengeInfo;
import com.douqu.game.core.entity.ext.MajorInfo;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.FunctionFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.LogUtils;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class TimeUtils {

    public static final String HOUR = "hour";
    public static final String MINUTE = "minute";
    public static final String SECOND = "second";
    public static final String MILLISECOND = "milliSecond";

    public static TimeData initTimeData(String value) throws IllegalArgumentException{
        TimeData timeData = new TimeData();
        timeData.timeValue = value;
        String[] strs = value.split(ConstantFactory.SEMICOLON);
        if (strs.length != 3){
            throw new IllegalArgumentException("value turn timeData error length ->" + strs.length);
        }
        //根据strs的第0位获取类型
        int[] timeArray = null;
        int type =  Integer.parseInt(strs[0]);
        if (type == E_TimeDataType.EVERYDAY_TIME.getCode()){
            timeData.type = E_TimeDataType.EVERYDAY_TIME;
            stringLenth(strs[1],4);
            timeArray = hourMin(strs[1]);
        }
        else if
        (type == E_TimeDataType.EVERYWEEK_TIME.getCode()){
            timeData.type = E_TimeDataType.EVERYWEEK_TIME;
            stringLenth(strs[1],5);
            timeArray = weekHourMin(strs[1]);
        }
        else if
        (type == E_TimeDataType.EVERYMOONDAY_TIME.getCode()){
            timeData.type = E_TimeDataType.EVERYMOONDAY_TIME;
            stringLenth(strs[1],6);
            timeArray = moonHourMin(strs[1]);
        }
        else if (type == E_TimeDataType.EVERYMOONWEEKDAY_TIME.getCode()){
            timeData.type = E_TimeDataType.EVERYMOONWEEKDAY_TIME;
            stringLenth(strs[1],6);
            timeArray = whichWeekOnMoon(strs[1]);
        }
        else if (type == E_TimeDataType.SPECIFIED_TIME.getCode()){
            timeData.type = E_TimeDataType.SPECIFIED_TIME;
            stringLenth(strs[1],12);
        }
        else if (type == E_TimeDataType.STARTSERVER_TIME.getCode()){
            timeData.type = E_TimeDataType.STARTSERVER_TIME;
            timeArray = new int[]{Integer.valueOf(strs[1])};
        }
        else
            throw new IllegalArgumentException("value turn timeData error type error type->" + type);

        timeData.timeArray = timeArray;

        //处理持续时间与单位
        keepTime(timeData,strs[2]);
        return timeData;
    }

    public static void stringLenth(String string,int length) throws IllegalArgumentException{
        if (string.length() != length)
            throw new IllegalArgumentException("value turn timeData error second option error sencondOption ->" + string);
    }

    public static int[] whichWeekOnMoon(String string){
        int[] array = new int[4];
        Integer which = Integer.valueOf(string.substring(0,1));
        if (which < 1 || which > 4)
            throw new IllegalArgumentException("value turn timeData error which week error which-> " + which);
        Integer week = Integer.valueOf(string.substring(1,2));
        if (which == 1){
            if (week != 7)
                throw new IllegalArgumentException("value tuen timeData error week error week->" + week);
        }
        array[0] = which;
        int[] wArray = weekHourMin(string.substring(1,string.length()));
        array[1] = wArray[0];
        array[2] = wArray[1];
        array[3] = wArray[2];
        return array;
    }

    public static int[] moonHourMin(String string) throws IllegalArgumentException{
        int[] array = new int[3];
        Integer day = Integer.valueOf(string.substring(0,2));
        if (day < 0 || day > 28)
            throw new IllegalArgumentException("value turn timeData error day error day->" + day);

        array[0] = day;
        int[] hArray = hourMin(string.substring(2,string.length()));
        array[1] = hArray[0];
        array[2] = hArray[1];
        return array;
    }

    public static int[] weekHourMin(String string) throws IllegalArgumentException{
        int[] array = new int[3];
        Integer week = Integer.valueOf(string.substring(0,1));
        if (week < 0 || week > 7)
            throw new IllegalArgumentException("value turn timeData error week error week->" + week);

        array[0] = week;
        int[] hArray = hourMin(string.substring(1,string.length()));
        array[1] = hArray[0];
        array[2] = hArray[1];
        return array;
    }

    public static int[] hourMin(String string) throws IllegalArgumentException{
        int[] array = new int[2];
        Integer hour = Integer.valueOf(string.substring(0,2));
        Integer minute = Integer.valueOf(string.substring(2,string.length()));
        if (hour < 0 || hour > 24)
            throw new IllegalArgumentException("value turn timeData error hour error hour->" + hour);

        if (minute < 0 || minute > 60)
            throw new IllegalArgumentException("value turn timeData error minute error minute->" + minute);

        array[0] = hour;
        array[1] = minute;
        return array;
    }

    public static void keepTime(TimeData timeData,String string) throws IllegalArgumentException{
        if (string.length() < 2){
            if (Integer.valueOf(string.trim()) == 0)
                return;
            throw new IllegalArgumentException("value turn timeData error keepTimeLength error keepTime:" + string + " length:" + string.length());
        }
        String unit = string.substring(0,2).toUpperCase();
        if (unit.equals(E_TimeDataUnit.MX.getMsg()))
            timeData.unit = E_TimeDataUnit.MX;
        else if (unit.equals(E_TimeDataUnit.SX.getMsg()))
            timeData.unit = E_TimeDataUnit.SX;
        else if (unit.equals(E_TimeDataUnit.HX.getMsg()))
            timeData.unit = E_TimeDataUnit.HX;
        else if (unit.equals(E_TimeDataUnit.DX.getMsg()))
            timeData.unit = E_TimeDataUnit.DX;
        else
            throw new IllegalArgumentException("value turn timeData error keepTime uiut error unit:" + string.substring(0,2));

        Integer keepTime =  Integer.valueOf(string.substring(2,string.length()));
        timeData.keepValue = keepTime;
    }

    public static boolean isArriveTime(TimeData timeData,long startTime){
        return isArriveTime(timeData,Calendar.getInstance(),startTime);
    }

    public static boolean isArriveTime(TimeData timeData,Calendar calendar,E_TimeDataType type){
        if (type == E_TimeDataType.EVERYWEEK_TIME){
            int week = CoreUtils.getWeek();
            if (week > timeData.timeArray[0]){
                return true;
            }
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            if (week == timeData.timeArray[0] && hour >= timeData.timeArray[1]){
                return true;
            }
        }
        return false;
    }

    public static boolean isArriveTime(TimeData timeData, Calendar calendar,long startTime){
        if (timeData == null){
            LogUtils.error("timeData is null ");
            return false;
        }
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int week = CoreUtils.getWeek();
        if (timeData.type == E_TimeDataType.EVERYDAY_TIME){
            //需要当前小时与分钟
            if (hour == timeData.timeArray[0] && minute == timeData.timeArray[1])
                return true;
            return false;
        }
        if (timeData.type == E_TimeDataType.EVERYWEEK_TIME){
            //需要当前周几 与小时与分钟
            if (week == timeData.timeArray[0] && hour == timeData.timeArray[1] && minute == timeData.timeArray[2])
                return true;
            return false;
        }
        if (timeData.type == E_TimeDataType.EVERYMOONDAY_TIME){
            //需要当前日(相对月) 小时 与 分钟
            int daily = calendar.get(Calendar.DAY_OF_MONTH);
            if (daily == timeData.timeArray[0] && hour == timeData.timeArray[1] && minute == timeData.timeArray[2])
                return true;
            return false;
        }
        if (timeData.type == E_TimeDataType.EVERYMOONWEEKDAY_TIME){
            //需要当前 第几周（相对月） 周几 小时 与 分钟
            int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
            if (weekOfMonth == timeData.timeArray[0] && week == timeData.timeArray[1] && hour == timeData.timeArray[2] && minute == timeData.timeArray[3])
                return true;
            return false;
        }
        if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
            //根据simpleDataFormat获取当前时间字符串做比较
            String currentTime = CoreUtils.getFormatTime(CoreUtils.YYYYMMDDHHMM,calendar.getTimeInMillis());
            if (currentTime.equals(timeData.timeValue))
                return true;
            return false;
        }
        if (timeData.type == E_TimeDataType.STARTSERVER_TIME){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
            if (Integer.valueOf(simpleDateFormat.format(calendar.getTime())) -
                    Integer.valueOf(simpleDateFormat.format(new Date(startTime))) == timeData.timeArray[0]){
                return true;
            }
            return false;

        }
        LogUtils.error("timeData type error type ->"  + timeData.type.getCode());
        return false;
    }

    /**
     * 获取活动时间
     * @param timeData
     * @param startTime
     * @return
     */
    public static long[] getActivityTime(TimeData timeData, long startTime)  {
        long[] time = new long[2];
        if (timeData == null){
            throw new NullPointerException("value timeData is null" );
        }
        if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CoreUtils.YYYYMMDDHHMM);
            Date date= null;
            try {
                date = simpleDateFormat.parse(timeData.timeValue);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (timeData.unit ==E_TimeDataUnit.SX){
                time[0] = date.getTime();
                time[1] = timeData.keepValue * 1000 +date.getTime();
                return time;
            }
            else if (timeData.unit == E_TimeDataUnit.MX){
                time[0] = date.getTime();
                time[1] =  timeData.keepValue * 1000 *60 +date.getTime();
               return time;
            }
            else if (timeData.unit == E_TimeDataUnit.HX){
                time[0] = date.getTime();
                time[1] = timeData.keepValue * 1000 *60 *60+date.getTime();
                return time;
            }
            else if (timeData.unit == E_TimeDataUnit.DX){
                time[0] = date.getTime();
                time[1] =  timeData.keepValue * 1000 *60*24 +date.getTime();
                return time;
            }
            else {
                throw new IllegalArgumentException("value turn timeData error keepTime uiut error unit:" + timeData.unit);
            }
        }
        if (timeData.type == E_TimeDataType.STARTSERVER_TIME) {
            //第几天开始
            int startDay =timeData.timeArray[0];
            long activityBeginTime = startTime + startDay* 24* 60 *60 *1000;
            long daySecond = 60 * 60 * 24 * 1000;
            activityBeginTime = activityBeginTime - (activityBeginTime + 8 * 60 * 60 * 1000) % daySecond;
            //持续天数
            int endDay = timeData.keepValue;
            long activityEndTime = activityBeginTime + endDay * 24* 60 *60 *1000;

            time[0] = activityBeginTime;
            time[1] = activityEndTime;
            return time;
        }else
        {
            throw new IllegalArgumentException("value type timeData error type:" + timeData.type);
        }
    }

    /**
     * 是否在活动时间内 目前只判断具体时间和开服时间两种情况
     * @param timeData
     * @param calendar
     * @param startTime
     * @return
     */
    public static boolean isInActivityTime(TimeData timeData, Calendar calendar, long startTime){
        if (timeData == null){
            LogUtils.error("timeData is null ");
            return false;
        }

        if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CoreUtils.YYYYMMDDHHMM);
            Date date= null;
            long beginTime;
            long endTime;
           long currentTime = calendar.getTime().getTime();
            try {
                date = simpleDateFormat.parse(timeData.timeValue);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (timeData.unit ==E_TimeDataUnit.SX){
                beginTime = date.getTime();
                endTime = timeData.keepValue * 1000 +date.getTime();
                return currentTime >= beginTime &&currentTime<=endTime;
            }
            else if (timeData.unit == E_TimeDataUnit.MX){
                beginTime = date.getTime();
                endTime =  timeData.keepValue * 1000 *60 +date.getTime();
                return currentTime >= beginTime &&currentTime<=endTime;
            }
            else if (timeData.unit == E_TimeDataUnit.HX){
                beginTime = date.getTime();
                endTime = timeData.keepValue * 1000 *60 *60+date.getTime();
                return currentTime >= beginTime &&currentTime<=endTime;
            }
            else if (timeData.unit == E_TimeDataUnit.DX){
                beginTime = date.getTime();
                endTime =  timeData.keepValue * 1000 *60*24 +date.getTime();
                return currentTime >= beginTime &&currentTime<=endTime;
            }
            else {
                throw new IllegalArgumentException("value turn timeData error keepTime uiut error unit:" + timeData.unit);
            }
        }
        if (timeData.type == E_TimeDataType.STARTSERVER_TIME){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
            if (Integer.valueOf(simpleDateFormat.format(calendar.getTime())) -
                    Integer.valueOf(simpleDateFormat.format(new Date(startTime))) >= timeData.timeArray[0]
                    && Integer.valueOf(simpleDateFormat.format(calendar.getTime())) -
                    Integer.valueOf(simpleDateFormat.format(new Date(startTime)))<=timeData.keepValue -1
                    ){
                return true;
            }
            return false;

        }
        LogUtils.error("timeData type error type ->"  + timeData.type.getCode());
        return false;
    }

    public static List<SGCommonProto.E_WEEK> getArriveWeek(TimeData timeData, TwoTuple<Long,Long> twoTuple){
        List<SGCommonProto.E_WEEK> list = new ArrayList<>();
        if (timeData.type == E_TimeDataType.EVERYDAY_TIME){
            list.add(SGCommonProto.E_WEEK.WEEK_MONDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_TUESDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_WEDNESDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_THURSDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_FRIDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_SATURDAY);
            list.add(SGCommonProto.E_WEEK.WEEK_SUNDAY);
        }
        if (timeData.type == E_TimeDataType.EVERYWEEK_TIME){
            list.add(SGCommonProto.E_WEEK.forNumber(timeData.timeArray[0]));
        }
        if (timeData.type == E_TimeDataType.EVERYMOONDAY_TIME){
            Calendar calendar = Calendar.getInstance();
            //日
            calendar.set(Calendar.DAY_OF_MONTH,timeData.timeArray[0]);
            if (calendar.getTimeInMillis() >= twoTuple.getFirst() && calendar.getTimeInMillis() <= twoTuple.getSecond())
                list.add(SGCommonProto.E_WEEK.forNumber(calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1));
        }
        if (timeData.type == E_TimeDataType.EVERYMOONWEEKDAY_TIME){
            Calendar calendar = Calendar.getInstance();
            if (calendar.get(Calendar.WEEK_OF_MONTH) == timeData.timeArray[0]){
                //同一周
                list.add(SGCommonProto.E_WEEK.forNumber(calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1));
            }
        }
        if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
            SimpleDateFormat dateFormat = new SimpleDateFormat(CoreUtils.YYYYMMDDHHMM);
            Date date = null;
            try {
                String[] a = timeData.timeValue.split(";");
                date = dateFormat.parse(a[1]);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (date != null){
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                if (calendar.getTimeInMillis() >= twoTuple.getFirst() && calendar.getTimeInMillis() <= twoTuple.getSecond())
                 list.add(SGCommonProto.E_WEEK.forNumber(calendar.get(Calendar.DAY_OF_WEEK) == 1 ? 7 :calendar.get(Calendar.DAY_OF_WEEK) - 1));
            }
        }
        return list;
    }

    public static SGCommonProto.ActivityHallColumn.Builder testActicityHallColumn(ActivityHallConfig config){
        //验证是否达到今天
        SGCommonProto.ActivityHallColumn.Builder builder = SGCommonProto.ActivityHallColumn.newBuilder();

        TimeData timeData = config.triggerTime;
        Calendar calendar = Calendar.getInstance();

        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int week = CoreUtils.getWeek();
        if (timeData.type == E_TimeDataType.EVERYDAY_TIME){
            builder.setActivityId(config.id);
            return builder;
        }
        if (timeData.type == E_TimeDataType.EVERYWEEK_TIME){
            //需要当前周几 与小时与分钟
            if (week == timeData.timeArray[0]){
                builder.setActivityId(config.id);
                return builder;
            }
        }
        if (timeData.type == E_TimeDataType.EVERYMOONDAY_TIME){
            //需要当前日(相对月) 小时 与 分钟
            int daily = calendar.get(Calendar.DAY_OF_MONTH);
            if (daily == timeData.timeArray[0]){
                builder.setActivityId(config.id);
                return builder;
            }
        }
        if (timeData.type == E_TimeDataType.EVERYMOONWEEKDAY_TIME){
            //需要当前 第几周（相对月） 周几 小时 与 分钟
            int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
            if (weekOfMonth == timeData.timeArray[0] && week == timeData.timeArray[1]){
                builder.setActivityId(config.id);
                return builder;
            }
        }
        if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
            //根据simpleDataFormat获取当前时间字符串做比较
            String[] ar = timeData.timeValue.split(";");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CoreUtils.YYYYMMDDHHMM);
            Date d = null;
            try {
                d = simpleDateFormat.parse(ar[1]);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (d != null){
                long start = d.getTime();
                //增加小时
                 d.setTime(d.getTime() + timeData.getKeepTime(MILLISECOND));
                long end = d.getTime();
                if (calendar.getTimeInMillis() >= start && calendar.getTimeInMillis() <= end ){
                    builder.setActivityId(config.id);
                    return builder;
                }
            }
        }
        return null;
    }

    /**
     * 这里必须clone一份数据进行操作 不要直接操作
     * @param column
     * @param player
     * @return
     */
    public static SGCommonProto.ActivityHallColumn.Builder getActivityHallColumn(SGCommonProto.ActivityHallColumn.Builder column, Player player){
        SGCommonProto.ActivityHallColumn.Builder builder = SGCommonProto.ActivityHallColumn.newBuilder();
        builder.setActivityId(column.getActivityId());
        builder.setStatus(SGCommonProto.E_ACTIVITY_HALL_STATUS.ACTIVITY_HALL_UNKNOWN);
        builder.setParam1(0);
        builder.setParam2(0);
        //开始验证
        ActivityHallConfig config = DataFactory.getInstance().getGameObject(DataFactory.ACTIVITY_HALL,builder.getActivityId());
        if (config != null){
            long now = DataFactory.currentTime;
            Calendar calendar = Calendar.getInstance();
            TimeData timeData = config.triggerTime;
            if (timeData.type == E_TimeDataType.EVERYDAY_TIME){
                calendar.set(Calendar.HOUR_OF_DAY,timeData.timeArray[0]);
                calendar.set(Calendar.MINUTE,timeData.timeArray[1]);
            }
            if (timeData.type == E_TimeDataType.EVERYWEEK_TIME || timeData.type == E_TimeDataType.EVERYMOONDAY_TIME){
                calendar.set(Calendar.HOUR_OF_DAY,timeData.timeArray[1]);
                calendar.set(Calendar.MINUTE,timeData.timeArray[2]);
            }
            if (timeData.type == E_TimeDataType.EVERYMOONWEEKDAY_TIME){
                calendar.set(Calendar.HOUR_OF_DAY,timeData.timeArray[2]);
                calendar.set(Calendar.MINUTE,timeData.timeArray[3]);
            }
            if (timeData.type == E_TimeDataType.SPECIFIED_TIME){
                calendar.set(Calendar.HOUR_OF_DAY,Integer.valueOf(timeData.timeValue.substring(8,10)));
                calendar.set(Calendar.MINUTE,Integer.valueOf(timeData.timeValue.substring(10,12)));
            }
            builder.setStatus(getStarus(now,calendar,timeData));
            if (config.functionid == FunctionFactory.WORLD_BOSS){
                ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
                builder.setParam1(challengeInfo.getBossData().getTodayTotalChallengeTimes() - challengeInfo.getBossData().getHasChallengeTimes());
                builder.setParam2(challengeInfo.getBossData().getTodayTotalChallengeTimes());
            }
            if (config.functionid == FunctionFactory.UNLOCK_HEROIC_SANCTUARY){
                ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
                builder.setParam1(challengeInfo.getHeroTempleData().getTodayTotalChallengeTime() - challengeInfo.getHeroTempleData().getTodayChallengeTimes());
                builder.setParam2(challengeInfo.getHeroTempleData().getTodayTotalChallengeTime());
            }
            if (config.functionid == FunctionFactory.UNLOCK_EXPEDITION_SYSTEM){
                ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
                builder.setParam1(challengeInfo.getExpeditionData().getTodayTotalResetTimes() - challengeInfo.getExpeditionData().getHasResetTimes());
                builder.setParam2(challengeInfo.getExpeditionData().getTodayTotalResetTimes());
            }
            if (config.functionid == FunctionFactory.UNLOCK_MAJOR_COLLECT){
                MajorInfo majorInfo = player.getMajorInfo();
                builder.setParam1(majorInfo.getCollectData().getMaxCollectTimes() - majorInfo.getCollectData().getHasCollectTimes());
                builder.setParam2(majorInfo.getCollectData().getMaxCollectTimes());
            }
            if (config.functionid == FunctionFactory.UNLOCK_COMPETITIVE_SYSTEM){
                ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
                builder.setParam1(challengeInfo.getArenaData().getTodayTotalChallengeTime() - challengeInfo.getArenaData().getTodayChallengeTimes());
                builder.setParam2(challengeInfo.getArenaData().getTodayTotalChallengeTime());
            }
            if (config.functionid == FunctionFactory.UNLOCK_Military_SYSTEM){
                ChallengeInfo challengeInfo = player.getExtInfo(ChallengeInfo.class);
                builder.setParam1(challengeInfo.getOfficialData().getTodayTotalChallengeTime() - challengeInfo.getOfficialData().getTodayChallengeTimes());
                builder.setParam2(challengeInfo.getOfficialData().getTodayTotalChallengeTime());
            }
        }
        return builder;
    }

    public static SGCommonProto.E_ACTIVITY_HALL_STATUS getStarus(long now,Calendar calendar,TimeData timeData){
        if (now < calendar.getTimeInMillis())
            return  SGCommonProto.E_ACTIVITY_HALL_STATUS.ACTIVITY_HALL_UNOPEN;
        else if (now < calendar.getTimeInMillis() + timeData.getKeepTime(MILLISECOND))
            return SGCommonProto.E_ACTIVITY_HALL_STATUS.ACTIVITY_HALL_ING;
        else
            return SGCommonProto.E_ACTIVITY_HALL_STATUS.ACTIVITY_HALL_OVER;
    }


    /**
     * 计算两个日期之间相差的天数
     * @param date1 较小的时间
     * @param date2  较大的时间
     * @return 相差天数
     */
    public static int dayBetween(Date date1,Date date2)
    {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try {
            date1=sdf.parse(sdf.format(date1));
            date2=sdf.parse(sdf.format(date2));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date1);
        long time1 = cal.getTimeInMillis();
        cal.setTime(date2);
        long time2 = cal.getTimeInMillis();
        long between_days=(time2-time1)/(1000*3600*24);
        return Integer.parseInt( String.valueOf(Math.abs(between_days)));
    }


    public static void main(String[] args) {

        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println(calendar.get(Calendar.MINUTE));
        System.out.println(calendar.get(Calendar.HOUR));
    }

}
